package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.AdministratorType;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.AdministratorTypeService;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller //@Controller注解是用spring容器生成 对象 默认对象名 administratorTypeController
//@RequestMapping("/administratorTypeController") //@RequestMapping 用户请求查找该资源使用的名字 网名 默认  /administratorTypeController
public class AdministratorTypeController {
	@Resource
    AdministratorTypeService administratorTypeService;

	@GetMapping("/getAlladministratorType")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<AdministratorType> getAllAdministratorType() throws Exception{
    	System.out.println("查询全部管理员类型");
    	return administratorTypeService.getAllAdministratorTypes();
    }

	@PostMapping("/addadministratorType")
	@ResponseBody
	public DTO<AdministratorType> addAdministratorType(@RequestBody AdministratorType administratorType) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加管理员类型成功");
		return administratorTypeService.addAdministratorType(administratorType);
	}
	@DeleteMapping("/deleteadministratorType/{ano}")
	@ResponseBody
    public DTO<AdministratorType> deleteAdministratorTypeByAno(@RequestBody @PathVariable("ano") String ano) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(ano+"删除管理员类型成功");
    	return administratorTypeService.deleteAdministratorTypeByAno(ano);
    }

	@GetMapping("/administratorTypeBy/{ano}")
	@ResponseBody
	public DTO<AdministratorType> getAdministratorTypeByAno(@PathVariable("ano") String ano) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println(ano+"根据主键查询管理员类型成功");
		return administratorTypeService.getAdministratorTypeByAno(ano);
	}

	@PatchMapping("/updateadministratorType")
	@ResponseBody
	public DTO<AdministratorType> updateAdministratorTypeByAno(@RequestBody AdministratorType administratorType) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改管理员类型成功");
		System.out.println(administratorType);
		return administratorTypeService.updateAdministratorTypeByAno(administratorType);
	}

	@RequestMapping("/administratorType/pageInfo")
	@ResponseBody
	public DTO<AdministratorType> getAdministratorTypeByPage(@SpringQueryMap PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("查询分页");
		return administratorTypeService.getAdministratorTypeByPage(pageInfo);
	}

}
